package com.ly.heart.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ly.common.core.domain.AjaxResult;
import com.ly.common.exception.CustomException;
import com.ly.common.utils.DateUtils;
import com.ly.common.utils.SecurityUtils;
import com.ly.common.utils.erp.SnowflakeIdWorker;
import com.ly.heart.domain.dto.KingSaleOutInventoryMaterialQueryDto;
import com.ly.heart.mapper.KingInvoiceReceivableDetailMapper;
import com.ly.heart.service.IKingInvoiceReceivableDetailService;
import org.springframework.stereotype.Service;
import com.ly.heart.domain.KingInvoiceReceivableDetailEntity;

import javax.annotation.Resource;

/**
 * 金蝶-发票-应收单/销售开票明细Service业务层处理
 *
 * @author wutao
 * @date 2024-06-26
 */
@Service
public class KingInvoiceReceivableDetailServiceImpl extends ServiceImpl<KingInvoiceReceivableDetailMapper, KingInvoiceReceivableDetailEntity> implements IKingInvoiceReceivableDetailService {

    @Resource
    private KingInvoiceReceivableDetailMapper kingInvoiceReceivableDetailEntityMapper;

    /**
     * 查询金蝶-发票-应收单/销售开票明细
     *
     * @param id 金蝶-发票-应收单/销售开票明细ID
     * @return 金蝶-发票-应收单/销售开票明细
     */
    @Override
    public KingInvoiceReceivableDetailEntity selectKingInvoiceReceivableDetailEntityById ( String id ) {
        return kingInvoiceReceivableDetailEntityMapper.selectKingInvoiceReceivableDetailEntityById ( id );
    }

    /**
     * 查询金蝶-发票-应收单/销售开票明细列表
     *
     * @param kingInvoiceReceivableDetailEntity 金蝶-发票-应收单/销售开票明细
     * @return 金蝶-发票-应收单/销售开票明细
     */
    @Override
    public List<KingInvoiceReceivableDetailEntity> selectKingInvoiceReceivableDetailEntityList ( KingInvoiceReceivableDetailEntity kingInvoiceReceivableDetailEntity ) {
        return kingInvoiceReceivableDetailEntityMapper.selectKingInvoiceReceivableDetailEntityList ( kingInvoiceReceivableDetailEntity );
    }

    /**
     * 新增金蝶-发票-应收单/销售开票明细
     * @param kingInvoiceReceivableDetailEntity 金蝶-发票-应收单/销售开票明细
     * @return 结果
     */
    @Override
    public AjaxResult insertKingInvoiceReceivableDetailEntity ( KingInvoiceReceivableDetailEntity kingInvoiceReceivableDetailEntity ) {
        kingInvoiceReceivableDetailEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        kingInvoiceReceivableDetailEntity.setCreateBy ( SecurityUtils.getLoginUser ().getUser ().getUserId () );
        kingInvoiceReceivableDetailEntity.setCreateTime ( DateUtils.getNowDate () );
        boolean save = this.save ( kingInvoiceReceivableDetailEntity );
        if ( ! save ) {
            throw new CustomException ( "新增应收单明细失败！" );
        }
        return AjaxResult.success ();
    }

    /**
     * 修改金蝶-发票-应收单/销售开票明细
     *
     * @param kingInvoiceReceivableDetailEntity 金蝶-发票-应收单/销售开票明细
     * @return 结果
     */
    @Override
    public int updateKingInvoiceReceivableDetailEntity ( KingInvoiceReceivableDetailEntity kingInvoiceReceivableDetailEntity ) {
        //kingInvoiceReceivableDetailEntity.setUpdateTime(DateUtils.getNowDate());
        //return kingInvoiceReceivableDetailEntityMapper.updateKingInvoiceReceivableDetailEntity(kingInvoiceReceivableDetailEntity);
        return 0;
    }

    /**
     * 批量删除金蝶-发票-应收单/销售开票明细
     *
     * @param ids 需要删除的金蝶-发票-应收单/销售开票明细ID
     * @return 结果
     */
    @Override
    public int deleteKingInvoiceReceivableDetailEntityByIds ( String[] ids ) {
        //return kingInvoiceReceivableDetailEntityMapper.deleteKingInvoiceReceivableDetailEntityByIds(ids);
        return 0;
    }

    /**
     * 删除金蝶-发票-应收单/销售开票明细信息
     *
     * @param id 金蝶-发票-应收单/销售开票明细ID
     * @return 结果
     */
    @Override
    public int deleteKingInvoiceReceivableDetailEntityById ( String id ) {
        //return kingInvoiceReceivableDetailEntityMapper.deleteKingInvoiceReceivableDetailEntityById(id);
        return 0;
    }

    @Override
    public KingInvoiceReceivableDetailEntity selectReceivableSumByOutStorageNo ( KingSaleOutInventoryMaterialQueryDto queryDto ) {
        return kingInvoiceReceivableDetailEntityMapper.selectReceivableSumByOutStorageNo ( queryDto );
    }
}
